#include "Face.h"

#include <sstream>

namespace MHX
{
	bool Face::parse(const TokenLine &tokens)
	{
		// Valid face line?
		if(tokens.size() < 4)
			return false;

		int index = 0;
		for(TokenIterator i = tokens.begin() + 1; i != tokens.end(), index < 4; i++, index++)
		{
			std::stringstream s(*i);
			s >> ind[index];
			if(s.fail())
			{
				if(index < 2)
					return false;
				break;
			}
		}

		if(index == 4)
			isQuad = true;
		else
			isQuad = false;

		return true;
	}

	size_t &Face::operator[](int i)
	{
		return ind[i];
	}

	const size_t &Face::operator[](int i) const
	{
		return ind[i];
	}
}